<?php
/**
 * @author Radovan Dvorsky
 * @version 20100514
 */
require_once ('Zend/Form.php');

class Form_Block_Add extends Zend_Form {
	
	private $_subjects;
	
	public function init(){
		
		$cache = Zend_Registry::get('cache');
		//$cacheName = My_Support::getCacheName('SubjectController','fetchAll'); ak sa zmeni na novu cache
		$cacheName = 'subjects';
		
		if(!($this->_subjects = $cache->load($cacheName))){
			$subjectMapper = new Db_Mapper_Subject();
			$order = $subjectMapper->getTable()->select()->order('name');
			$this->_subjects = $subjectMapper->fetchAll($order);			
			$cache->save($this->_subjects,$cacheName,array(get_class($subjectMapper)));
		}	
		
	}
	
	public function __construct($options = null) {
		parent::__construct ($options);
		
		$this->addDecorator('fieldset',array('legend' => 'Vytvoriť odborný blok'));
		
		$blockName = new Zend_Form_Element_Text('name');
		$blockName->addFilter('StripTags')
		->addFilter('StringTrim')
		->setRequired(true)
		->setAllowEmpty(false)
		->setLabel('Meno bloku: ');

		$subjects = new Zend_Form_Element_Multiselect('subjects');
		$subjects->setLabel('Predmety v odbornom bloku');
		$subjects->setAllowEmpty(false);
		$subjects->setDescription("Pre viacnásobný výber použite klávesu CTRL");
		
		foreach($this->_subjects as $subject){
			$subjects->addMultiOption(
				$subject['sid'],
				$subject['name']
			);
		}	

		$this->addElements(array($blockName,$subjects));
	
	}
}

?>